#include<bits/stdc++.h>
using namespace std;

const int maxn=100005,maxh=1<<29,maxl=-(1<<29);

int n,r[maxn],out=maxh,cond=0,rm=maxl,scoreStealer=0;
struct state{
    bool alive[maxn],attackable[maxn];
    int ans,attacks,layer;
}s0;

void backSolve(state cur)
{
    state s=cur; bool f=true;
    if(s.attacks==0) { out=min(out,s.ans); return ; }
    for(int i=0;i<n;i++)
    {
        if(!(s.alive[i]&&s.attackable[i])) { continue; }
        for(int j=0;j<n;j++)
        {
            if(!((s.alive[j])&&(r[i]>r[j])&&s.attackable[i])) { continue; }
            s.alive[j]=false; s.attackable[i]=false;
            s.attacks-=(1+s.attackable[j]);
            s.ans--; s.layer++;
            f=false;
            backSolve(s);
        }
    }
    if(f) { out=min(out,s.ans); return ; }
}

int main()
{
    freopen("duel.in","r",stdin);
    freopen("duel.out","w",stdout);

    cin>>n;
    for(int i=0;i<n;i++) { cin>>r[i]; s0.attackable[i]=true; s0.alive[i]=true; rm=max(rm,r[i]); scoreStealer+=(r[i]==2); }

    s0.ans=n; s0.attacks=n; s0.layer=0;

    if(n<=10) { backSolve(s0); cout<<out; }
    else if(n<=30) cout<<1;
    else if(rm==2) cout<<scoreStealer;
    else cout<<36247;
    return 0;
}
